package com.qianli.cashmama.trade.domain.model;

import com.qianli.cashmama.trade.common.enums.TradeActionEnum;
import com.qianli.cashmama.trade.common.enums.TradeStatusEnum;
import com.qianli.cashmama.trade.domain.StateMachine;
import com.qianli.cashmama.trade.domain.Transition;

/**
 * 交易的状态机
 * <p>
 * Created by scrack on 2017/7/21.
 */
public class TradeBaseState {
    public static final StateMachine STATE_TRANSITION_DEF = new StateMachine(new Transition[]
            {
                    /**初始化-> 创建交易 */
                    new Transition(TradeStatusEnum.INIT.getStatus(), TradeActionEnum.CREATED.getCode(),
                            TradeStatusEnum.CREATE_SUCCESS.getStatus()),
                    /**初始化-> 创建交易 */
                    new Transition(TradeStatusEnum.INIT.getStatus(), TradeActionEnum.AUDIT_RECEIPT.getCode(),
                            TradeStatusEnum.AUDIT_WATTING.getStatus()),

                    /** 创建成功-> 等待信审回执*/
                    new Transition(TradeStatusEnum.CREATE_SUCCESS.getStatus(), TradeActionEnum.AUDIT_RECEIPT.getCode(),
                            TradeStatusEnum.AUDIT_WATTING.getStatus()),


                    /** 信审通过->打款中 */
                    new Transition(TradeStatusEnum.AUDIT_WATTING.getStatus(), TradeActionEnum.PAY_CASH_RECEIPT.getCode(),
                            TradeStatusEnum.LOAN_WAITTING.getStatus()),

                    new Transition(TradeStatusEnum.AUDIT_WATTING.getStatus(), TradeActionEnum.AUDIT_RECEIPT.getCode(),
                            TradeStatusEnum.AUDIT_REJECT.getStatus()),

                    new Transition(TradeStatusEnum.AUDIT_WATTING.getStatus(), TradeActionEnum.AUDIT_RECEIPT.getCode(),
                            TradeStatusEnum.LOAN_WAITTING.getStatus()),
                    /** 银行卡错误->重新发起放款 */
                    new Transition(TradeStatusEnum.LOAN_WAITTING.getStatus(), TradeActionEnum.PAY_CASH_RECEIPT.getCode(),
                            TradeStatusEnum.PAY_RETRY.getStatus()),

                    new Transition(TradeStatusEnum.PAY_RETRY.getStatus(), TradeActionEnum.LOAN_RETRY.getCode(),
                            TradeStatusEnum.LOAN_WAITTING.getStatus()),

                    new Transition(TradeStatusEnum.PAY_RETRY.getStatus(), TradeActionEnum.LOAN_RETRY.getCode(),
                            TradeStatusEnum.AUDIT_WATTING.getStatus()),

                    /** 审核通过-放款失败-*/
                    new Transition(TradeStatusEnum.LOAN_WAITTING.getStatus(), TradeActionEnum.PAY_CASH_RECEIPT.getCode(),
                            TradeStatusEnum.PAY_RETRY.getStatus()),

                    new Transition(TradeStatusEnum.PAY_RETRY.getStatus(), TradeActionEnum.PAY_CASH_RECEIPT.getCode(),
                            TradeStatusEnum.PAY_RETRY.getStatus()),

                    new Transition(TradeStatusEnum.PAY_RETRY.getStatus(), TradeActionEnum.LOAN_RETRY.getCode(),
                            TradeStatusEnum.MANUAL_CLOSED.getStatus()),

                    /** 打款中->待还款*/
                    new Transition(TradeStatusEnum.LOAN_WAITTING.getStatus(), TradeActionEnum.PAID_RECEIPT.getCode(),
                            TradeStatusEnum.REPAYMENT_WATTING.getStatus()),

                    /** 待还款-逾期还款*/
                    new Transition(TradeStatusEnum.REPAYMENT_WATTING.getStatus(), TradeActionEnum.PAID_RECEIPT.getCode(),
                            TradeStatusEnum.OVERDUE_REPAYMENT.getStatus()),
                    /** 待还款->正常还款成功*/
                    new Transition(TradeStatusEnum.REPAYMENT_WATTING.getStatus(), TradeActionEnum.PAID_RECEIPT.getCode(),
                            TradeStatusEnum.NORMAL_REPAYMENT.getStatus()),
                    /** 待还款->提前还款成功*/
                    new Transition(TradeStatusEnum.REPAYMENT_WATTING.getStatus(), TradeActionEnum.PAID_RECEIPT.getCode(),
                            TradeStatusEnum.EARLY_REPAYMENT.getStatus()),
                    /** 逾期中->逾期还款成功*/
                    new Transition(TradeStatusEnum.OVERDUE.getStatus(), TradeActionEnum.PAID_RECEIPT.getCode(),
                            TradeStatusEnum.OVERDUE_REPAYMENT.getStatus()),

                    /** 待还款->逾期*/
                    new Transition(TradeStatusEnum.REPAYMENT_WATTING.getStatus(), TradeActionEnum.OVERDUE_RECEIPT.getCode(),
                            TradeStatusEnum.OVERDUE.getStatus()),


                    /** 逾期->逾期还款成功*/
                    new Transition(TradeStatusEnum.OVERDUE.getStatus(), TradeActionEnum.OVERDUE_RECEIPT.getCode(),
                            TradeStatusEnum.OVERDUE_REPAYMENT.getStatus()),

                    /** 信审通过 >> 审核中->待提现*/
                    new Transition(TradeStatusEnum.AUDIT_WATTING.getStatus(), TradeActionEnum.AUDIT_RECEIPT.getCode(),
                            TradeStatusEnum.PENDING_WITHDRAWAL.getStatus()),
                    /**
                     * 用户提现确认 11变3
                    */
                    new Transition(TradeStatusEnum.PENDING_WITHDRAWAL.getStatus(), TradeActionEnum.WITHDRAWAL_CONFIRM.getCode(),
                            TradeStatusEnum.LOAN_WAITTING.getStatus()),

                    new Transition(TradeStatusEnum.PENDING_WITHDRAWAL.getStatus(), TradeActionEnum.WITHDRAWAL_CONFIRM.getCode(),
                            TradeStatusEnum.REPAYMENT_WATTING.getStatus()),

                    new Transition(TradeStatusEnum.OVERDUE.getStatus(), TradeActionEnum.OVERDUE_TO_REPAYMENT_WAITTING.getCode(),
                            TradeStatusEnum.REPAYMENT_WATTING.getStatus()),

                    /** 展期成功->逾期的改为未逾期*/
                    new Transition(TradeStatusEnum.OVERDUE.getStatus(), TradeActionEnum.EXTENSION_RECEIPT.getCode(),
                            TradeStatusEnum.REPAYMENT_WATTING.getStatus()),

                    new Transition(TradeStatusEnum.REPAYMENT_WATTING.getStatus(), TradeActionEnum.EXTENSION_RECEIPT.getCode(),
                            TradeStatusEnum.REPAYMENT_WATTING.getStatus()),
            }
    );

    public static StateMachine getStateTransitionDef() {
        return STATE_TRANSITION_DEF;
    }
}
